<?php

/**
 * @Author: Azaz；QQ：826355918
 * @Date:   2018-12-11 23:09:08
 * @Last Modified by:   Azaz
 * @Last Modified time: 2019-02-22 02:25:49
 */

namespace app\common\model;
use \think\Model;

class WxAdmin extends Model{

	protected $pk = 'id';
    protected $name = 'wxAdmin';

    
    /**
     * 数据完成
    **/
    public function saveData($data = [],$type = 'add'){
       
        if( empty( $data['weixin'] ) ) return $this->error = '微信号不能为空';
        if( empty( $data['urlid'] ) ) return $this->error = '绑定域名不能为空';

        if($type == 'add'){
            $id = $state = $this->allowField(true)->save($data);
        }
        if($type == 'edit'){
            $state = $this->allowField(true)->save($data,['id'=>$data['id']]);
            $id = $data['id'];
        }
        if($state){
            return $id;
        }else{
            $this->error = $this->getError() ? $this->getError() : '没有可修改的数据！';
            return false;
        }
        return false;
    }


    /**
     * 网页信息修改
    **/
    public function modifyInfo($data,$userInfo){

        $state = $this->allowField(true)->save($data,['id'=>$userInfo['id']]);
        if($state){
            return true;
        }else{
            $this->error = $this->getError() ? $this->getError() : '没有可修改的数据！';
            return false;
        }
        return false;
    }



}